using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.IO;
using System.Windows.Forms;

using Mighty.Lib;
using Mighty.Lib.Document;
using Mighty.Lib.Controls;

using Castle.Windsor;

namespace Mighty
{
    public partial class MightyMainWindow : Form
    {

        #region Main() method
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            //MightyConfig config = ConfigurationManager.GetSection("example") as MightyConfig;

            // TODO: add command line argument parsing.. how?

            // window container setup
            IWindsorContainer container = new WindsorContainer();
            container.AddComponent("MightyConfigProvider", typeof(MightyConfigProvider));
            container.AddComponent("OpenFileProvider", typeof(IOpenProvider), typeof(DefaultOpenHandler));
            container.AddComponent("SaveFileProvider", typeof(ISaveProvider), typeof(DefaultSaveProvider));
            container.AddComponent("DocumentProvider", typeof(IDocumentRepository), typeof(DefaultDocumentRepository));
            

            // SCRAPE FOR PLUGINS HERE

            // REGISTER PLUGIN DOCS/CONTROLS/HOOKS WITH CONTAINER

            // setup default doc stuff....
            // .. for now we don't take any input from the command line, just spin up
            // our new default doc
            List<IDocument> docList = new List<IDocument>();

            // if, determined above by argument parsing, we are going to load a document, then
            // let's load that sucker here

            // otherwise we pass in the list and document repo

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new MightyMainWindow(docList, container.Resolve<IDocumentRepository>()));
        }

        #endregion

        #region properties
        private Container _container = null;
        public Container IocContainer
        {
            get
            {
                return _container;
            }
        }
        
        private List<IDocument> _docs;
        public List<IDocument> Documents
        {
            get
            {
                return _docs;
            }
        }



        private IDocumentRepository _documentRepo = null;
        public IDocumentRepository DocumentRepository
        {
            get
            {
                return _documentRepo;
            }
        }
        #endregion

        #region ctors
        public MightyMainWindow(IDocumentRepository documentRepo)
        {
            _documentRepo = documentRepo;
            _docs = new List<IDocument>();
            InitializeComponent();
            IntegrateDocuments();
            this.Refresh();
        }

        public MightyMainWindow(List<IDocument> initialDocs, IDocumentRepository documentRepo)
        {

            _documentRepo = documentRepo;
            _docs = initialDocs;

            InitializeComponent();
            IntegrateDocuments();
            this.Refresh();
        }
        #endregion

        #region event handlers
        private void MainWindow_Resize(object sender, EventArgs e)
        {
            EditorTabControl.SetBounds(EditorTabControl.Location.X, EditorTabControl.Location.Y, this.Width - 18, this.Height - 85);
            EditorTabControl.Refresh();
            foreach (TabPage page in EditorTabControl.TabPages)
            {
                page.Controls[0].SetBounds(page.Controls[0].Location.X, page.Controls[0].Location.Y, EditorTabControl.Size.Width - 13, EditorTabControl.Size.Height - 32);
            }
        }

        #endregion

    }
}